package collection

var identity = func(value T) T {return value}

func CountBy(array []T, iteratee ...func(value T) T) map[T]int {
	iterateeFunc := identity
	if len(iteratee) > 0 {
		iterateeFunc = iteratee[0]
	}
	ret := map[T]int{}
	for _, value := range array {
		ret[iterateeFunc(value)]++
	}
	return ret
}